package com.loser.utils.trace;


import cn.hutool.core.util.IdUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;

public class TraceUtil {

    private static final SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
    private static final AtomicLong count = new AtomicLong();

    public static String getTraceId() {
        return format.format(new Date()) + "-" + UUID.randomUUID().toString().replace("-", "");
    }

    public static String getTraceId(String ip) {
        return format.format(new Date()) + '-' + ip + "-" + IdUtil.fastSimpleUUID() + "-" + count.getAndIncrement();
    }

}
